package fr.generali.accueilclient.gwt.client.ui.components.form.button;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.web.bindery.event.shared.HandlerRegistration;



public class ActionButtonBase extends Button {

	protected static Resources res = GWT.create(Resources.class);

	private HandlerRegistration registration;
	
	private Command command;
	
	public ActionButtonBase() {
		setStyleName(res.style().btn());
		res.style().ensureInjected();
	}

	/**
	 * @param command
	 *            la command associé au click handler.
	 */
	public void setCommand(final Command _command) {
		
		command = _command;

		if (registration != null) {
			registration.removeHandler();
		}

		registration = addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				command.execute();
			}
		});
	}
	
	public Command getCommand() {
		return command;
	}

}
